import React, { Component } from 'react'
import Navbar from './Navbar'
import Sidebar from './Sidebar'

export default class App extends Component {
  state = {
    sidebarOpened: true,
  }
  render() {
    return (
      <div>
        <Navbar>
          <button onClick={() => this.handleClick()}>click</button>
        </Navbar>
        {this.state.sidebarOpened && <Sidebar></Sidebar>}
      </div>
    )
  }

  handleClick = () => {
    console.log('子组件中的 click', this.state.sidebarOpened)
    this.setState({ sidebarOpened: !this.state.sidebarOpened })
  }
}

/**
 * 1. 为了复用
 * 2. 一定程度上减少父子通信
 */
